home *** CD-ROM | disk | FTP | other *** search
/ CD Classic 39 / CD CLASSIC #39 (1998).iso / EMPRESA / visio / Vistdstd / Install / Data.Z / ProdView.CLS < prev    next >
Text File  |  1997-06-26  |  11KB  |  278 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "ProductView"
  6. Attribute VB_GlobalNameSpace = True
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. ' -----------------------------------------------------------------------------
  11. ' Copyright (C) 1997 Visio Corporation. All rights reserved.
  12. '
  13. ' You have a royalty-free right to use, modify, reproduce and distribute
  14. ' the Sample Application Files (and/or any modified version) in any way
  15. ' you find useful, provided that you agree that Visio has no warranty,
  16. ' obligations or liability for any Sample Application Files.
  17. ' -----------------------------------------------------------------------------
  18. Private tvcTree As TreeView
  19. Private WithEvents theDocument As Visio.Document
  20. Attribute theDocument.VB_VarHelpID = -1
  21. Private WithEvents theApplication As Visio.Application
  22. Attribute theApplication.VB_VarHelpID = -1
  23. Private totalCost As Currency
  24.  
  25. Private Sub Class_Initialize()
  26. ' Event happens when an instance of this class module is created.
  27.  
  28. ' Show the form and set its tree instance
  29.  
  30.     frmConfig.Show 0
  31.     Set frmConfig.tvcProduct = Me
  32.     Set tvcTree = frmConfig.TreeView1
  33. End Sub
  34.  
  35. Public Sub PopulateTree()
  36. 'Read the drawing, excluding background pages, and add all shapes that have
  37. 'a custom property "Cost" to the tvcTree list.
  38.     Dim i As Integer, j As Integer
  39.     
  40.     ' Populate with Existing Shapes
  41.     
  42.     For i = 1 To theDocument.Pages.Count
  43.         If Not (theDocument.Pages(i).Background) Then
  44.             For j = 1 To theDocument.Pages(i).Shapes.Count
  45.                 AddCostItem theDocument.Pages(i).Shapes(j)
  46.             Next j
  47.         End If
  48.     Next i
  49.     
  50. End Sub
  51.  
  52. Public Sub SetStatus(str As String, arg1 As Variant)
  53. 'Set the contents of the status bar
  54.     frmConfig.StatusBar1.Panels(1).Text = str & ":" & Format(arg1, "Currency")
  55.     frmConfig.StatusBar1.Refresh
  56.        
  57. End Sub
  58.  
  59. Public Sub UnloadUI()
  60.     ' close the form if it is open
  61.    Unload frmConfig
  62. End Sub
  63.  
  64. Public Sub InitWith(ByVal theDoc As Visio.Document)
  65. 'The starting point for this application
  66.     Set theDocument = theDoc
  67.     Set theApplication = theDoc.Application
  68.     ' Parse the existing pages and add to the list
  69.     Call PopulateTree
  70. End Sub
  71.  
  72. Private Sub theApplication_AfterModal(ByVal app As Visio.IVApplication)
  73. 'Captures the changes to custom properties from the Visio custom properties
  74. 'dialog box. If the user changes a custom property the modal custom properties
  75. 'dialog box is displayed. When it is closed we treat that event the same as if
  76. 'the user clicked on the node in the tree (which refreshes its custom properties
  77. 'list.
  78.  
  79.     'SelectedItem will be nothing if we are modifying the properties of the page.
  80.     If Not tvcTree.SelectedItem Is Nothing Then
  81.         ClickedOnNode (tvcTree.SelectedItem.Text)
  82.     End If
  83. End Sub
  84.  
  85. Private Sub theApplication_SelectionChanged(ByVal Window As Visio.IVWindow)
  86.     Dim shpObj As Visio.Shape
  87.     On Error GoTo ErrorHandler
  88.     
  89.     If Window.Selection.Count = 1 Then
  90.         'One item is selected - update the list
  91.         Set shpObj = Window.Selection.Item(1)
  92.         
  93.         'NOTE: Does not work when new shape added because the selection changed
  94.         'event occurs before the shape added event - thus the need for the error
  95.         'handler. The shape added event will occur after and the shape's properties
  96.         'will then be displayed.
  97.         tvcTree.Nodes(shpObj.Name).Selected = True
  98.         ShowListProperties
  99.     Else
  100.         'Either nothing is selected or more than one item is selected
  101.         frmConfig.ListView1.ListItems.Clear
  102.         Set frmConfig.TreeView1.SelectedItem = Nothing
  103.     End If
  104.     Exit Sub
  105. ErrorHandler:
  106.     frmConfig.ListView1.ListItems.Clear
  107.     Set frmConfig.TreeView1.SelectedItem = Nothing
  108.     Exit Sub
  109. End Sub
  110.  
  111. Private Sub theDocument_BeforeDocumentClose(ByVal doc As Visio.IVDocument)
  112. 'The ConfigView application must be stopped if Visio is closed.
  113.     Unload frmConfig
  114.     End
  115. End Sub
  116.  
  117. Private Sub theDocument_BeforeSelectionDelete(ByVal Selection As Visio.IVSelection)
  118. 'A shape, or shapes, is about to be deleted from the drawing.
  119. 'Delete each from the tvcTree.
  120.     Dim i As Integer
  121.     
  122.     For i = 1 To Selection.Count
  123.         DelCostItem Selection(i)
  124.     Next i
  125. End Sub
  126.  
  127. Private Sub theDocument_ShapeAdded(ByVal Shape As Visio.IVShape)
  128. 'A new shape has been added to the drawing. Check to see that it has
  129. 'a custom property "Cost" and if so add it to the list.
  130.     AddCostItem Shape
  131. End Sub
  132.  
  133. Public Sub ClickedOnNode(shpName As String)
  134. 'This procedure is called when the user selects an item from the tvcTree
  135.         
  136.     ' Select shape in Drawing.  The custom properties will be displayed as
  137.     'a result of the selection changed event which will occur by setting the
  138.     'Visio selection.
  139.     SetVisioSelection (shpName)
  140.  
  141. End Sub
  142.  
  143. Public Sub AddCostItem(Shape As Visio.Shape)
  144. 'Add an item to the tvcTree only if it has the custom property "Cost"
  145. 'and the shape is visible in the drawing. Check the shape's layer
  146. 'property to determine if it currently visible.
  147.     Dim tempNode As Node
  148.     Dim Icon As String
  149.  
  150.     If Shape.CellExists("prop.cost", False) And IsVisible(Shape) Then
  151.         Select Case Shape.Master.Name
  152.             Case "Corner Desk": Icon = "Desk"
  153.             Case "30"" Chest": Icon = "Dresser"
  154.             Case "Dresser": Icon = "Dresser"
  155.             Case "72"" Book Shelf": Icon = "Hutch"
  156.             Case "35.5"" Door Chest": Icon = "DoorChest"
  157.             Case "42"" Corner Hutch": Icon = "Hutch"
  158.             Case "42"" Hutch": Icon = "Hutch"
  159.             Case Else
  160.                 Icon = "Open"
  161.         End Select
  162.         Set tempNode = tvcTree.Nodes.Add(, , Shape.Name, Shape.Name, Icon)
  163.         'Increment the total cost figure in the status bar
  164.         totalCost = totalCost + CDbl(Shape.Cells("prop.cost").ResultStr(""))
  165.         Me.SetStatus "Cost", totalCost
  166.     End If
  167. End Sub
  168.  
  169. Public Sub DelCostItem(Shape As Visio.Shape)
  170. 'Delete an item from the tvcTree and decriment the total cost figure in the status bar.
  171. 'If the Prop.Cost cell does not exist then the shape cannot be part of the list.
  172.     If Shape.CellExists("prop.cost", False) Then
  173.         totalCost = totalCost - CDbl(Shape.Cells("prop.cost").ResultStr(""))
  174.         tvcTree.Nodes.Remove Shape.Name
  175.         Me.SetStatus "Cost", totalCost
  176.     End If
  177. End Sub
  178.  
  179. Public Sub SetVisioSelection(shpName As String)
  180. 'Set the Visio drawing window to show shpName as the currently selected shape.
  181.  
  182.     'The error test is necessary since this routine is called following the
  183.     'Application.After_Modal event. This event is triggered when Visio is
  184.     'closed, and unsaved changes are in the drawing. Closing the modal
  185.     'dialog leads to the calling of this routine.
  186.     On Error Resume Next
  187.     
  188.     With theDocument.Application
  189.         .ScreenUpdating = 0
  190.         .ActiveWindow.Select .ActivePage.Shapes.Item(shpName), visSelect + visDeselectAll '2 + 256
  191.         'Try zooming in on the drawing. This will center the current selection
  192.         'if it is not already visible within the drawing window.
  193.         .ActiveWindow.Zoom = .ActiveWindow.Zoom
  194.         .ScreenUpdating = 1
  195.     End With
  196.  
  197. End Sub
  198.  
  199. Public Sub ShowListProperties()
  200. 'List the custom properties of the selected shape
  201.     Dim ssrcArray(1 To 5 * 4) As Integer
  202.     Dim unitsArray(1 To 5) As Variant
  203.     Dim resultLabels() As Variant
  204.     Dim resultValues() As Variant
  205.     Dim i As Integer
  206.     Dim nrows As Integer
  207.  
  208.     'Clear any current custom properties display
  209.     frmConfig.ListView1.ListItems.Clear
  210.     
  211.     'Get the first selected item. This routine should only be called
  212.     'when there is exactly one selected item. See theApplication_SelectionChanged
  213.     'event procedure.
  214.     With theDocument.Application.ActiveWindow.Selection(1)
  215.         nrows = .RowCount(visSectionProp)
  216.         'Get the label properties for each row. For a detailed description
  217.         'see the GetResults method in the Visio Automation Reference help file.
  218.         For i = 0 To 4
  219.             If i > nrows - 1 Then
  220.                 ssrcArray(i * 4 + 1) = visInvalShapeID
  221.             Else
  222.                 ssrcArray(i * 4 + 1) = .ID
  223.             End If
  224.             ssrcArray(i * 4 + 2) = visSectionProp
  225.             ssrcArray(i * 4 + 3) = visRowProp + i
  226.             ssrcArray(i * 4 + 4) = visCustPropsLabel
  227.         Next i
  228.         theDocument.Application.ActivePage.GetResults ssrcArray, visGetStrings, unitsArray, resultLabels
  229.         
  230.         'Get the value properties for each row - only the cell property changes
  231.         For i = 0 To nrows - 1
  232.             ssrcArray(i * 4 + 4) = visCustPropsValue
  233.             If resultLabels(i) = "Height" Then
  234.                 unitsArray(i + 1) = visInches
  235.             Else
  236.                 unitsArray(i + 1) = visGetStrings
  237.             End If
  238.         Next i
  239.         theDocument.Application.ActivePage.GetResults ssrcArray, visGetStrings, unitsArray, resultValues
  240.         
  241.         'Add the property label and its value to the listview control
  242.         For i = 0 To nrows - 1
  243.             Set li = frmConfig.ListView1.ListItems.Add(, , resultLabels(i))
  244.             'The Select Case controls the formating of custom property values
  245.             Select Case resultLabels(i)
  246.               Case "Cost"
  247.                 li.SubItems(1) = Format(CDbl(resultValues(i)), "$0")
  248.               Case "Height"
  249.                 li.SubItems(1) = Format(Val(resultValues(i)), "0.## in.")
  250.               Case Else
  251.                 li.SubItems(1) = resultValues(i)
  252.             End Select
  253.         Next i
  254.          
  255.     End With
  256. End Sub
  257.  
  258. Public Function IsVisible(Shape As Visio.Shape)
  259. 'Determine if a shape is visible by checking its layer properties
  260. 'to see that it is on a visible layer or on no layer at all
  261.     Dim i As Integer
  262.     Dim bVisible As Boolean
  263.     
  264.     'The shape is visible if it not in any layer. It is initialized to
  265.     'false if it is a member of any layer.
  266.     bVisible = (Shape.LayerCount = 0)
  267.     
  268.     For i = 1 To Shape.LayerCount
  269.         'When any visible is layer is found, this is sufficient to exit
  270.         If Shape.Layer(i).CellsC(visLayerVisible).Result(visNumber) <> 0 Then
  271.             bVisible = True
  272.             Exit For
  273.         End If
  274.     Next i
  275.  
  276.     IsVisible = bVisible
  277. End Function
  278.